<template>
  <div
    class="E-page-singer"
    v-loading="load"
    element-loading-text="拼命加载中..."
    element-loading-spinner="el-icon-loading"
  >
    <el-row :gutter="15">
      <el-col :span="8" v-for="(item, index) in dataArr" :key="index">
        <div class="singer-card bg-image-cover">
          <img v-lazy="item.img1v1Url" />
          <p class="text-ellipsis">
            {{item.name}}
            <span v-if="item.alias.length">({{item.alias[0]}})</span>
          </p>
        </div>
      </el-col>
    </el-row>
    <E-pagination @change="(p,l)=>getData(keywords,p,l)" :total="total" background />
  </div>
</template>

<script>
import Tool from '@/plug-in/Tool';

export default {
  props: ['keywords'],
  components: {
    'E-pagination': () => import('@/components/high-reuse/E-pagination')
  },
  data() {
    return {
      load: false,
      total: 0,
      dataArr: []
    };
  },
  methods: {
    getData(keywords, offset, limit) {
      this.load = true;
      this.$api.get('search', {
        keywords, offset, limit, type: 100
      }, true).then(({ result }) => {
        this.total = result.artistCount;
        this.dataArr = result.artists;
        console.log(result);
      }).finally(() => { this.load = false; });
    },
    download(index, dataArr) {},
    durationFormatter(row, column) {
      const total = row.duration / 1000;
      return Tool.durationFormat(total);
    },
    randomTagType() {
      const arr = ['', 'success', 'info', 'warning', 'danger'];
      const len = arr.length;
      return arr[Tool.randomNum(0, len)];
    }
  }
};
</script>

<style lang="scss" scoped>
.E-page-singer {
  & > .el-row {
    padding: 15px 15px 0 15px;
    & > .el-col {
      margin-bottom: 20px;
      .singer-card {
        position: relative;
        display: flex;
        $size: 60px;
        padding: 5px;
        border-radius: 5px;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
        cursor: pointer;
        img {
          width: $size;
          height: $size;
          flex: 0 0 $size;
          object-fit: cover;
        }
        p {
          height: $size;
          line-height: $size;
          flex-grow: 1;
          padding: 0 20px;
          font-size: 15px;
          & > span {
            color: #bbb;
          }
        }
      }
    }
  }
}
</style>
